<template>
  <div class="hm-login">
    <van-nav-bar title="面经登录"></van-nav-bar>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div class="hm-login-btn">
        <van-button type="primary" size="large" color="#fa6d1d"
          >提交</van-button
        >
      </div>
    </van-form>

    <div class="gore">
      <div class="right"></div>
      <router-link to="/register" class="left">注册账号</router-link>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "HmLogin",
  data() {
    return {
      tel: "",
      username: "lixin",
      digit: "",
      number: "",
      password: "123456",
    };
  },
  methods: {
    async onSubmit() {
      // http://interview-api-t.itheima.net/h5/user/login
      const res = await axios({
        url: "http://interview-api-t.itheima.net/h5/user/login",
        method: "post",
        data: {
          username: this.username,
          password: this.password,
        },
      });
      console.log(res);
      if (res.status == 200) {
        localStorage.setItem("token", res.data.data.token);
        this.$router.push("/layout/article/recommend");
        this.toast = true;
      }
    },
  },
  created() {
    // axios({
    //   url: "http://interview-api-t.itheima.net/h5/user/login",
    //   method: "post",
    //   data: {
    //     username: this.username,
    //     password: this.password,
    //   },
    //   header: {
    //     "Content-Type": "application/json",
    //   },
    // });
  },
};
</script>

<style lang="less" scoped>
.hm-login {
  .hm-login-btn {
    padding: 10px 10px;
    margin-top: 20px;
  }
  .gore {
    display: flex;
    .right {
      flex: 1;
    }
    .left {
      min-width: 100px;
      color: #006699;
    }
  }
}
</style>
